package com.googlecode.jkorpos.lingpipe;

import com.aliasi.corpus.Parser;

import com.aliasi.corpus.parsers.MedPostPosParser;

import com.aliasi.io.FileExtensionFilter;

import com.aliasi.util.Files;
import com.aliasi.util.Iterators;

import java.io.File;
import java.io.IOException;
import java.io.StringReader;

import java.util.Iterator;

import org.xml.sax.InputSource;
public class SejongPosCorpus implements PosCorpus{

    private final File mMedPostDir;

    public SejongPosCorpus(File medPostDir) {
	mMedPostDir = medPostDir;
    }

    public Iterator sourceIterator() {
	return new MedPostSourceIterator(mMedPostDir);
    }

    public Parser parser() {
	return new SejongPosParser();
    }
			  
    public static class MedPostSourceIterator extends Iterators.Buffered {
	private final File[] mFiles;
	private int mNextFileIndex = 0;
	public MedPostSourceIterator(File medPostDir) {
	    mFiles = medPostDir.listFiles(new FileExtensionFilter("txt", false));
	}
	public Object bufferNext() {
	    if (mNextFileIndex >= mFiles.length) return null;
	    try { 
		String url = Files.fileToURLName(mFiles[mNextFileIndex++]);
		return new InputSource(url);
	    } catch (IOException e) {
		return null;
	    }
	}
    }
}
